package com.easylinkin.linkappapi.childinspection.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.easylinkin.linkappapi.childinspection.service.InspectionRecordService;
import com.easylinkin.linkappapi.childinspection.vo.BaseVo;
import com.easylinkin.linkappapi.childinspection.vo.InspectionRecordVo;
import com.easylinkin.linkappapi.common.model.RequestModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;

/**
 * @author linWenLe
 * @Date: 2024/4/11
 * @Description: 巡检记录管理
 */
@RestController
@RequestMapping("/inspectionRecord")
public class InspectionRecordController extends ApiController {

    @Resource
    private InspectionRecordService inspectionRecordService;

    /***
     * 巡检记录列表
     * @return
     */
    @RequestMapping("getList")
    public RestMessage getTaskList(@RequestBody RequestModel<BaseVo> restPage) {
        return RestBuilders.successBuilder(inspectionRecordService.getList(restPage)).build();
    }

    /***
     * 新增巡检记录
     * @return
     */
    @RequestMapping("insert")
    public RestMessage insert(@RequestBody InspectionRecordVo entity) {
        return  RestBuilders.successBuilder().data(inspectionRecordService.insert(entity)).build();
    }

    /**
     * 扫描二维码获取巡检点信息,判断是否是巡检员
     * @return
     */
    @RequestMapping("getPointAndUserInfo")
    @ApiOperation("查询巡检点和人员信息")
    public RestMessage getUserInfo(String pointId) {
        return RestBuilders.successBuilder((this.inspectionRecordService.getPointAndUserInfo(pointId))).build();
    }

    @RequestMapping("findRecord")
    @ApiOperation("查询最新的巡检记录")
    public RestMessage findRecord(String pointId) {
        return RestBuilders.successBuilder((this.inspectionRecordService.findRecord(pointId))).build();
    }


    @RequestMapping("findRecordAndDanger")
    @ApiOperation("查询是否存在巡检记录及隐患")
    public RestMessage findRecordAndDanger(String pointId) {
        return RestBuilders.successBuilder((this.inspectionRecordService.findRecordAndDanger(pointId))).build();
    }


    /***
     * 巡检任务统计
     * @return
     */
    @RequestMapping("getTaskCount")
    @ApiOperation("统计巡检记录")
    public RestMessage getTaskCount(String taskId) {
        return  RestBuilders.successBuilder(inspectionRecordService.getTaskCount(taskId)).build();
    }

    /**
     * 通过主键查询单条隐患数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectHidden")
    @ApiOperation("查询单条")
    public RestMessage selectOne(String id) {
        return RestBuilders.successBuilder((this.inspectionRecordService.selectOne(id))).build();
    }
}
